package com.crawler.clent;

import java.util.Map;

import com.google.common.collect.Maps;

public class CrawlerManager {
	
	public static final Map<String , Crawler> crawlerPool = Maps.newConcurrentMap();
	
	public static void remove(String key){
		if(isCrawling(key))
			crawlerPool.remove(key);
	}
	
	public static void put(String key,Crawler crawler){
		crawlerPool.put(key, crawler);
	}
	
	public static Crawler get(String key){
		Crawler crawler = null;
		if(isCrawling(key)){
			crawler = crawlerPool.get(key);
		}else{
			crawler = new JDCrawler();
			put(key, crawler);
		}
		return crawler;
	}
	
	public static boolean isCrawling(String key){
		return crawlerPool.containsKey(key) ? true : false ;
	}
	
	public static int crawlerSize(){
		return crawlerPool.size();
	}
	
	public static void removeAll(){
		crawlerPool.clear();
	}
	
}
